﻿using LibBinary.FileDeclaration.Text;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LibBinary.Serialization.BinaryInText
{
    public class LengthProviderProvider : IObjectDeclarationProvider
    {
        private static LengthProviderProvider _Instance = new LengthProviderProvider();
        public static LengthProviderProvider Instance { get { return _Instance; } }

        private LengthProviderProvider()
        {
        }

        public StructuredDeclaration Get(string name)
        {
            return declarationDict[name];
        }

        private static Dictionary<string, StructuredDeclaration> declarationDict = new Dictionary<string, StructuredDeclaration>();

        static LengthProviderProvider()
        {
            declarationDict.Add("const", MakeConst());
            declarationDict.Add("reference", MakeReference());
        }

        private static StructuredDeclaration MakeConst()
        {
            return new StructuredDeclaration(new StructuredField[] {
                new StructuredField { FieldName = "value", Declaration = new PrimitiveDeclaration(PrimitiveType.Int32) },
            });
        }

        private static StructuredDeclaration MakeReference()
        {
            return new StructuredDeclaration(new StructuredField[] {
                new StructuredField { FieldName = "index", Declaration = new PrimitiveDeclaration(PrimitiveType.Int32) },
            });
        }
    }
}
